﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BattleCamera : MonoBehaviour {

    Camera m_Cam;
    public Camera Camera 
    {
        get
        {
            if (m_Cam == null)
                m_Cam = GetComponentInChildren<Camera>();
            return m_Cam;
        }
    }
    Animator m_Animator;
    public Animator animator
    {
        get
        {
            if (m_Animator == null)
                m_Animator = GetComponentInChildren<Animator>();

            return m_Animator;
        }
    }

    protected Vector3 m_TargetPos = Vector3.zero;

    protected bool inMoving;
    
    protected virtual void Awake()
    {

    }

    /// <summary>
    /// 当前正在使用的时间
    /// </summary>
    [SerializeField]
    private float m_CurrentTimeDuration = 0.2f;

    public virtual void SetTargetPos(Vector3 targetPos)
    {
        if ((m_TargetPos - targetPos).sqrMagnitude > 0.001f)
        {
            m_TargetPos = targetPos;
            
            inMoving = true;
        }
    }
    [SerializeField]
    protected float m_LerpSpeed = .05f;

    void LerpToTargetPos()
    {
        this.transform.position = Vector3.Lerp(this.transform.position, m_TargetPos, m_LerpSpeed);
    }



    protected virtual void Update()
    {
        if(inMoving)
            this.LerpToTargetPos();
    }



}
